package persist

import (
	"fmt"
	"gitee.com/git_public/vfaith/fount/env"
	"os"
)

type config struct {
	username string
	password string
	host     string
	port     int
	dbName   string
}

func (da *config) readConfig(configName string) *config {
	if configName == "" {
		configName = "DB"
	}
	// 从配置文件读取数据库连接信息
	da.username = os.Getenv(fmt.Sprintf("%s_USERNAME", configName))
	da.password = os.Getenv(fmt.Sprintf("%s_PASSWORD", configName))
	da.host = os.Getenv(fmt.Sprintf("%s_HOST", configName))
	da.port = env.GetEnvAsInt(fmt.Sprintf("%s_PORT", configName), 3306)
	da.dbName = os.Getenv(fmt.Sprintf("%s_NAME", configName))

	return da
}
